<?php 
class Category_manager extends Abstract_manager
{
	function __construct()
	{
		parent::__construct();
		$this->table = "categories";
        	$this->config = array(
               array(
                     'field'   => 'title', 
                     'label'   => 'Titel', 
                     'rules'   => 'required'
                  )
            );
        $this->form_validation->set_rules($this->config);
        $this->post_data['alias'] = strtolower(url_title($this->input->post("title"), 'dash'));
        $this->post_data['title_nl'] = $this->input->post('title');
	}
	
    function readItems()
    {
      // return parent::readItems();
    	return $this->db->get_where($this->table, array("is_default !=" => 1))->result();
    }
    
    function getArticles($category_id)
    {
    	$articles =  $this->db->get_where("articles", array("category_id" => $category_id))->result();
    	$output = array();
    	
    	foreach ($articles as $article)
    	{
    		$data = array();
    		$data['article:title'] = $article->title;
    		$data['article:fulltext'] = word_limiter($article->fulltext, 30);
    		$data['article:id']  = $article->id;
    		$data['article:alias']  = $article->alias;
    	
    		array_push($output, $data);	
    	}
    	return $output;
    	
    }
}

